|
1
|
|
|
'use strict'; |
|
2
|
|
|
|
|
3
|
|
|
import * as fs from 'fs'; |
|
4
|
|
|
import * as path from 'path'; |
|
5
|
|
|
import { assert } from 'chai'; |
|
6
|
|
|
import Parser from '../../src/Parser'; |
|
7
|
|
|
import { Input, Lexer } from '../../src/Lexer'; |
|
8
|
|
|
import helloWorldAst from '../Data/hello_world.ast.json'; |
|
9
|
|
|
import pkg from '../../package.json'; |
|
10
|
|
|
|
|
11
|
|
|
/** @test {Parser} */ |
|
12
|
|
|
describe(`${pkg.name}/Parser/Parser`, () => { |
|
13
|
|
|
/** @test {Parser#constructor} */ |
|
14
|
|
|
describe('#constructor', () => { |
|
15
|
|
|
it('Create a new instance of type Parser', () => { |
|
16
|
|
|
const input = new Input('+Hello World'), |
|
17
|
|
|
lexer = new Lexer(input), |
|
18
|
|
|
parser = new Parser(lexer); |
|
19
|
|
|
|
|
20
|
|
|
assert.instanceOf(parser, Parser); |
|
21
|
|
|
}); |
|
22
|
|
|
}); |
|
23
|
|
|
|
|
24
|
|
|
/** @test {Parser#parse} */ |
|
25
|
|
|
describe('#parse', () => { |
|
26
|
|
|
it('Parse program', () => { |
|
27
|
|
|
const sourceCode = fs.readFileSync(path.join(__dirname, '..', 'Data', 'hello_world.bot'), { |
|
28
|
|
|
encoding : 'utf8', |
|
29
|
|
|
flag : 'r' |
|
30
|
|
|
}), |
|
31
|
|
|
input = new Input(sourceCode), |
|
32
|
|
|
lexer = new Lexer(input), |
|
33
|
|
|
parser = new Parser(lexer), |
|
34
|
|
|
code = parser.parse(); |
|
35
|
|
|
|
|
36
|
|
|
assert.isObject(code); |
|
37
|
|
|
assert.deepEqual(code, helloWorldAst); |
|
38
|
|
|
}); |
|
39
|
|
|
}); |
|
40
|
|
|
|
|
41
|
|
|
/** @test {Parser#replaceStringSubstitution} */ |
|
42
|
|
|
describe('#replaceStringSubstitution', () => { |
|
43
|
|
|
it('Should replace the string substitution character in a given string', () => { |
|
44
|
|
|
assert.notInclude(Parser.replaceStringSubstitution('I $ you because you are so $!'), '$'); |
|
45
|
|
|
}); |
|
46
|
|
|
}); |
|
47
|
|
|
|
|
48
|
|
|
/** @test {Parser#replaceWildcard} */ |
|
49
|
|
|
describe('#replaceWildcard', () => { |
|
50
|
|
|
it('Should replace the wildcard substitution character in a given string', () => { |
|
51
|
|
|
assert.notInclude(Parser.replaceWildcard('What do you think about * and *?'), '*'); |
|
52
|
|
|
}); |
|
53
|
|
|
}); |
|
54
|
|
|
}); |
|
55
|
|
|
|